﻿using Cl.Model.Results;
using Cl.Model.Systems.Dictionary;
using Cl.Service.Service.User.Departments;
using Cl.Service.Service.User.Roles;
using Cl.WebApi.Controllers;
using Cl.WebApi.SwaggerModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Cl.WebApi.Areas.Admin.Systems
{
    /// <summary>
    /// 字典管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = Grouping.OpenGroup)]
    public class DictionaryController : BaseController
    {

        #region 构造函数

        IRoleService _roleService;
        IDepartmentService _departmentService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public DictionaryController(IRoleService roleService, IDepartmentService departmentService)
        {
            _roleService = roleService;
            _departmentService = departmentService;
        }

        #endregion




        /// <summary>
        /// 获取角色字典
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultInfoModel GetRoleDic()
        {
            List<DictionaryDto> result = new List<DictionaryDto>();
            var list = _roleService.GetRoleList();
            result = list.Select(x => new DictionaryDto { Key = x.Id, Value = x.Name }).ToList();
            return GetResult.Success("Success", result);

        }

        /// <summary>
        /// 获取部门字典
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ResultInfoModel GetDepartmentListDic()
        {
            List<DictionaryDto> result = new List<DictionaryDto>();
            var list = _departmentService.GetDepartmentList();
            result = list.Select(x => new DictionaryDto { Key = x.Id, Value = x.Name }).ToList();
            return GetResult.Success("Success", result);

        }
    }
}
